package com.ftf.tp.message.application.service.impl;

import com.ftf.tp.common.constants.NoticeTypeEnum;
import com.ftf.tp.message.application.assembler.NoticeAssembler;
import com.ftf.tp.message.application.dto.message.SupportMessage;
import com.ftf.tp.message.application.dto.message.domain.ActionEvent;
import com.ftf.tp.message.application.service.NoticeApplicationService;
import com.ftf.tp.message.application.service.NoticeGenerateService;
import com.ftf.tp.message.domain.directMessage.dos.NoticeEventDO;
import com.ftf.tp.message.domain.directMessage.service.impl.NoticeEventService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author tanghao
 * @date 2022/9/1
 */
@Service
public class NoticeApplicationServiceImpl implements NoticeApplicationService {

    @Resource
    private NoticeEventService noticeEventService;

    @Resource
    private Map<String, NoticeGenerateService> noticeGenerateServiceMap;

    /**
     * 通知事件生成
     *
     * @param message 事件
     */
    @Override
    public void noticeEventCreate(SupportMessage message) {
        ActionEvent actionEvent = message.getData();
        NoticeEventDO noticeEventDO = NoticeAssembler.INSTANCE.eventToDO(actionEvent);
        noticeEventService.save(noticeEventDO);
        NoticeGenerateService noticeGenerateService = noticeGenerateServiceMap.get(NoticeTypeEnum.implByCode(noticeEventDO.getAction()));

        //生成通知
        noticeGenerateService.generate(noticeEventDO);
    }
}
